package com.kantboot.system.user.listener;

import com.kantboot.system.user.event.BalanceChangeEvent;
import com.kantboot.system.user.service.ISysUserBalanceService;
import jakarta.annotation.Resource;
import jakarta.transaction.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 余额变化监听器
 */
@Slf4j
@Component
public class BalanceChangeListener {

    @Resource
    private ISysUserBalanceService service;


    /**
     * 余额变化事件
     * @param event 事件
     */
    @Async
    @Transactional
    @EventListener
    public void onApplicationEvent(BalanceChangeEvent event) {
        service.changeBalanceInner(event.getRecord(),true);
    }

}
